import datetime
from uuid import UUID

from pydantic import BaseModel, constr, EmailStr

from models import Role, Status


class StatusOut(BaseModel):
    id: int
    status: Status
    datetime: datetime.datetime


class OrganizationAutocomplete(BaseModel):
    name: str


class RespIn(BaseModel):
    description: constr(min_length=1, strip_whitespace=True)


class RespOut(RespIn):
    id: int


class ReqBase(BaseModel):
    topic: constr(min_length=1, strip_whitespace=True)
    description: constr(strip_whitespace=True) | None = None


class ReqCreate(ReqBase):
    pass


class OrganizationOut(BaseModel):
    id: int
    name: str
    inn: str


class OrganizationCreate(BaseModel):
    name: constr(min_length=1, strip_whitespace=True)
    inn: constr(min_length=10, max_length=10, strip_whitespace=True)


class UserShort(BaseModel):
    id: UUID
    name: str
    organization: OrganizationOut


class Req(ReqBase):
    id: int
    current_status: StatusOut
    user: UserShort

    class Config:
        from_attributes = True


class ReqShort(BaseModel):
    id: int
    topic: str
    current_status: StatusOut
    user: UserShort


class UserOut(UserShort):
    email: str
    role: Role


class UserAuth(BaseModel):
    login: constr(min_length=1, strip_whitespace=True)
    password: constr(min_length=1, strip_whitespace=True)


class UserRegistration(BaseModel):
    name: constr(min_length=1, strip_whitespace=True)
    password: constr(min_length=1, strip_whitespace=True)
    organization: constr(min_length=1, strip_whitespace=True)
    email: EmailStr


class User(UserRegistration):
    id: UUID


class TokenSchema(BaseModel):
    access_token: str


class TokenPayload(BaseModel):
    sub: str = None
    exp: int = None


class UserWithTokens(BaseModel):
    user: UserOut
    tokens: TokenSchema


class PasswordRecovery(BaseModel):
    email: EmailStr


class NewPassword(BaseModel):
    password: constr(min_length=1, strip_whitespace=True)